package priv.conceit.sc.hoxton.file.handle.compress;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import priv.conceit.sc.hoxton.common.util.FileSuffixUtil;
import priv.conceit.sc.hoxton.file.config.FileProperties;

/**
 * sc-hoxton
 *
 * @author Conceit
 * 2020/6/11 增加方法
 * @since 1.0.0, 2020/6/11
 */
@Component
public class CompressHandleFactory {

	@Autowired
	RarCompressHandle rarCompressHandle;

	@Autowired
	SevenZCompressHandle sevenZCompressHandle;

	@Autowired
	ZipCompressHandle zipCompressHandle;

	@Autowired
	TarCompressHandle tarCompressHandle;

	@Autowired
	FileProperties fileProperties;

	/**
	 * create 根据文件后缀 获取对应压缩文件处理方式
	 *
	 * @param suffix
	 * @return priv.conceit.sc.hoxton.file.handle.compress.AbsCompressHandle
	 * @author conceit
	 * @date 2020/6/15 16:26
	 */
	public AbsCompressHandle create(String suffix){
		if(FileSuffixUtil.suffixAnyMatch(FileSuffixUtil.SEVENZ_COMPRESS_SUFFIXS,suffix,fileProperties.getPreview().getIgnoreCase())){
			return sevenZCompressHandle;
		}else if(FileSuffixUtil.suffixAnyMatch(FileSuffixUtil.ZIP_COMPRESS_SUFFIXS,suffix,fileProperties.getPreview().getIgnoreCase())){
			return zipCompressHandle;
		} else if(FileSuffixUtil.suffixAnyMatch(FileSuffixUtil.RAR_COMPRESS_SUFFIXS,suffix,fileProperties.getPreview().getIgnoreCase())){
			return rarCompressHandle;
		}else if(FileSuffixUtil.suffixAnyMatch(FileSuffixUtil.TAR_COMPRESS_SUFFIXS,suffix,fileProperties.getPreview().getIgnoreCase())){
			return tarCompressHandle;
		}
		//todo 都不是 则调用下载方法
		return null;
	}

}
